package com.menggudf.service.impl;

import com.menggudf.entity.FamilyInfo;
import com.menggudf.mapper.FamilyInfoDao;
import com.menggudf.service.FamilyInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (FamilyInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:28
 */
@Service("familyInfoService")
public class FamilyInfoServiceImpl implements FamilyInfoService {
    @Resource
    private FamilyInfoDao familyInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FamilyInfo queryById(Integer id) {
        return this.familyInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param familyInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FamilyInfo> queryByPage(FamilyInfo familyInfo, PageRequest pageRequest) {
        long total = this.familyInfoDao.count(familyInfo);
        return new PageImpl<>(this.familyInfoDao.queryAllByLimit(familyInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param familyInfo 实例对象
     * @return 实例对象
     */
    @Override
    public FamilyInfo insert(FamilyInfo familyInfo) {
        this.familyInfoDao.insert(familyInfo);
        return familyInfo;
    }

    /**
     * 修改数据
     *
     * @param familyInfo 实例对象
     * @return 实例对象
     */
    @Override
    public FamilyInfo update(FamilyInfo familyInfo) {
        this.familyInfoDao.update(familyInfo);
        return this.queryById(familyInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.familyInfoDao.deleteById(id) > 0;
    }
}
